package com.peak.distribution.web.validator.method;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;

import com.peak.distribution.web.validator.ValidateRuleMethod;
import com.peak.spring.boot.tools.Converts;
import com.peak.spring.boot.tools.Emptys;

public class SameTo implements ValidateRuleMethod {

	@Value("${validate.rule.same.to}")
	private String errorMessage;
	
	private String other;
	
	@Override
	public boolean execute(Object value) {
		return StringUtils.equals(Converts.toString(value), this.other);
	}

	@Override
	public String getErrorMessageTemplate() {
		return Emptys.isEmpty(this.errorMessage) ? "{0}的两次输入不一致" : this.errorMessage;
	}

	@Override
	public void setParams(Map<String, Object> param) {
		this.other = Converts.toString(param.get("other"));
	}

}
